package com.hioove.core.reflect;

import com.hioove.core.model.base.config.MethodSupport;
import com.hioove.core.util.ClassUtils;

import java.util.List;
import java.util.Optional;

/**
 * 代理类
 */
public interface Proxy {

    Proxy INSTANCE = getInstance();

    String CGLIB_PROXY = "com.hioove.core.reflect.CglibProxy";

    String JDK_PROXY = "com.hioove.core.reflect.JdkProxy";

    Proxy setPointcut(List<MethodSupport> pointcut);

    Proxy setBefore(List<MethodSupport> before);

    Proxy setAfter(List<MethodSupport> after);

    Proxy setAfterReturning(List<MethodSupport> afterReturning);

    Proxy setAfterThrowing(List<MethodSupport> afterThrowing);

    Proxy setAround(List<MethodSupport> around);

    <T> T create(Class<T> clazz);

    static Proxy getInstance() {
        Optional<Object> obj = Optional.ofNullable(ClassUtils.createObj(CGLIB_PROXY));
        return (Proxy) (obj.isPresent() ? obj.get() : obj.orElseGet(ClassUtils.createObj(JDK_PROXY)));
    }

}
